package org.eliza.base.coroutinesx.flow

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

object Flowx {

}

suspend fun Flowx.Filter() {
    flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9).onEach { v ->
        println("onEach $v")
    }.filter { v ->
        v % 2 == 0
    }.map { v ->
        v * 10
    }.take(5).collect { v ->
        println("--> collect $v")
    }
}

@OptIn(ExperimentalCoroutinesApi::class)
suspend fun Flowx.Compose() {
    flow {
        emit(flowOf(1, 2, 3))
        emit(flowOf(4, 5, 6))
    }.flattenConcat().collect{v->
        println("collectConcat $v")
    }
}

fun main() {
    runBlocking {
        Flowx.Filter()
    }
}